/*
 * tcp_timer.c
 *
 *  Created on: 2009-5-26
 *      Author: tian
 */

#include"mytcp.h"
#include<time.h>
#include<errno.h>

int tcp_timer(struct tcpcb *ptcpcb,int i){
	//printf("in tcp_timer:state:%d,t:%d,%d,%d,%d;i%d\n",ptcpcb->tcp_state,ptcpcb->timer[0],ptcpcb->timer[1],ptcpcb->timer[2],ptcpcb->timer[3],i);
	if(i==1){
		ptcpcb->timer[3]++;
		if(ptcpcb->timer[3]==3){
			tcp_input(NULL,NULL,ptcpcb,close_sock);
		}
		else{
			ptcpcb->seq--;
			tcp_output(&(ptcpcb->lasthdr),ptcpcb->sndbuf,ptcpcb->sndlen,ptcpcb);
		}
	}
	else{
		tcp_input(NULL,NULL,ptcpcb,timeout);
	}
	return 0;
}
